package com.example.myapp;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {
    private static final int NOTIFYID = 0x123;
    private Button button;
    @SuppressLint({"UnspecifiedImmutableFlag", "NotificationPermission"})
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = findViewById(R.id.btn);
        button.setOnClickListener(new View.OnClickListener() {
            @SuppressLint({"ObsoleteSdkInt", "NotificationPermission"})
            @Override
            public void onClick(View v) {
                NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                Notification.Builder notification = new Notification.Builder(MainActivity.this);
                notification.setAutoCancel(true);//
                notification.setSmallIcon(R.drawable.ic_launcher_background);
                notification.setContentTitle("奖励百万红包");
                notification.setContentText("点击查看详情");
                notification.setWhen(System.currentTimeMillis());
                notification.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE);

                Intent intent = new Intent(MainActivity.this, MainActivity2.class);

                PendingIntent pi = PendingIntent.getActivity(MainActivity.this,0,intent,0);
                notification.setContentIntent(pi);
                notificationManager.notify(NOTIFYID,notification.build());
            }
        });
    }
}


